//
//  LLMallHotActivityCollectionViewCell.m
//  lrlzapp
//
//  Created by dl on 16/3/1.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLMallHotActivityCollectionViewCell.h"
#import "LLMenuItemDataCollectionViewModel.h"

@interface LLMallHotActivityCollectionViewCell ()
@property(nonatomic, strong) LLMenuItemDataCollectionViewModel *viewModel;
@property(nonatomic, strong) UIScrollView *scrollView;
@end

@implementation LLMallHotActivityCollectionViewCell
@synthesize scrollView;

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.ll_width, self.ll_height - SUIT_H(8))];
        scrollView.backgroundColor = [UIColor whiteColor];
        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.alwaysBounceHorizontal = YES;
        [self.contentView addSubview:scrollView];
    }
    return self;
}

- (void)bindViewModel:(LLMenuItemDataCollectionViewModel *)viewModel {
    self.viewModel = viewModel;

    // 图片列表
    NSArray<LLMenuItemDataViewModel *> *items = viewModel.itemList;
    for (int i = 0; i < items.count; i++) {
        CGRect frame = CGRectMake(SUIT_W(14) + i * (SUIT_W(148) + SUIT_W(10)),
                0,
                SUIT_W(148),
                SUIT_W(98));
        LLUIImageView *imgView = [[LLUIImageView alloc] initWithFrame:frame];
        [imgView setImageUrlStr:items[i].imageUrl];
        [scrollView addSubview:imgView];
    }
    CGFloat scrollWidth = scrollView.ll_width;
    CGFloat sumWidth = (SUIT_W(148) + SUIT_W(10)) * items.count - SUIT_W(10) + 2 * SUIT_W(14);
    if (sumWidth > scrollWidth) {
        scrollView.contentSize = CGSizeMake(sumWidth, SUIT_H(98));
    }
}

@end
